package org.xu.enums;


import com.core.enums.StringEnum;

import java.util.Arrays;
import java.util.Optional;

/**
 * 年检状态枚举
 * @author liuxiaoxu
 */
public enum YearlyInspectStatusEnum implements StringEnum {
    INVOLVED("involved", "涉案"),
    SEAL_UP("seal_up", "查封"),
    NOT_ANNUAL_INSPECT("not_annual_inspect", "不年检"),
    PASS_ANNUAL_INSPECT("pass_annual_inspect", "年检通过"),
    FAIL_ANNUAL_INSPECT("fail_annual_inspect", "年检未通过"),
    WAIT_ANNUAL_INSPECT("wait_annual_inspect", "待年检"),
    NOT_EXIST_ANNUAL_INSPECT("not_exist_annual_inspect", "暂无年检信息"),
    ;
    YearlyInspectStatusEnum(String value, String text) {
        this.value = value;
        this.text = text;
    }

    private final String value;
    private final String text;

    @Override
    public String getValue() {
        return value;
    }

    public String getCode() {
        return this.value;
    }

    public String getText() {
        return text;
    }

    public static String getNameByCode(String code){
        Optional<YearlyInspectStatusEnum> first = Arrays.stream(YearlyInspectStatusEnum.values()).filter(t -> t.getCode().equals(code)).findFirst();
        return first.map(YearlyInspectStatusEnum::getText).orElse(null);
    }

    public static YearlyInspectStatusEnum getInstanceByName(String name){
        Optional<YearlyInspectStatusEnum> first = Arrays.stream(YearlyInspectStatusEnum.values()).filter(t -> t.getText().equals(name)).findFirst();
        return first.orElse(null);
    }
    public static YearlyInspectStatusEnum getInstanceByCode(String code){
        Optional<YearlyInspectStatusEnum> first = Arrays.stream(YearlyInspectStatusEnum.values()).filter(t -> t.getCode().equals(code)).findFirst();
        return first.orElse(null);
    }
}
